package cn.wolfcode.trip.base.domain;


import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * 地区Model
 */
@Getter
@Setter
public class Region extends BaseDomain {
    /**
     * 普通
     */
    public static final Integer STATE_COMMON = 0;
    /**
     * 热门
     */
    public static final Integer STATE_HOT = 1;
    /**
     * 禁用
     */
    public static final Integer STATE_DISABLE = -1;

    /**
     * 地区名
     */
    private String name;
    /**
     * 上级地区
     */
    private Region parent;
    /**
     * 状态，默认普通
     */
    private Integer state=STATE_COMMON;


    public String getJson() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        //需要更改
        map.put("parent", parent);
        map.put("state", state);
        return JSONUtil.toJSONString(map);
    }

    /**
     * treeView插件，Object2tree转换
     * @return
     */
    public Map toTreeMap() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("text", name);
        map.put("json", getJson());
        //判断是否热门，显示推荐
        if (STATE_HOT.equals(state)) {
            map.put("tags", new String[]{"推荐"});
        }
        map.put("lazyLoad", true);
        return map;
    }

}